import os
import logging

logger = logging.getLogger('config')
from webSite import models

# 本地配置参数
class Local():
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'xxx',
            'USER': 'xxx',
            'PASSWORD': 'xxx',
            'HOST': '127.0.0.1',
            'PORT': '3306',
        },
    }
class Remote():
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'xxx',
            'USER': 'xxx',
            'PASSWORD': 'xxx',
            'HOST': 'w.rdc.sae.sina.com.cn',
            'PORT': '3307',
        }
    }

class webSiteInfo():
    scrapyObj=[
        {
            'url': ["http://huway.com/news/"],
           'pageFlag': 'news',
           'path': '//div[@class="cont"]',
           'originName': '中华户外网',
           'originUrl': "http://huway.com",
           'type': 'policyNews',
           'group': 'hotspot'
        },
        {
          'url': ['http://outdoor.sohu.com/'],
          'pageFlag': 'sohu',
          'path': '//div[@id="contentText"]',
          'originName': '搜狐户外',
          'originUrl': "http://outdoor.sohu.com",
          'type': 'policyNews',
          'group': 'hotspot'
        },
        {
          'url': ['http://you.ctrip.com','http://you.ctrip.com/travels/fall/t1.html','http://you.ctrip.com/travels/fall/t2.html','http://you.ctrip.com/travels/fall/t100.html'],
          'pageFlag': 'travels',
          'path': '//div[@class="ctd_content"]',
          'originName': '携程旅游网游记',
          'originUrl': "http://you.ctrip.com",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': ['http://travel.163.com/'],
          'pageFlag': '',
          'path': '//div[@class="post_body"]',
          'originName': '芒果网易旅游',
          'originUrl': "http://travel.163.com",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': ['http://www.cnta.com.cn/xxfb','http://www.cnta.com.cn'],
          'pageFlag': '',
          'path': '//div[@class="zhu_main"]',
          'originName': '中华人民共和国国家旅游局',
          'originUrl': "http://www.cnta.com.cn",
          'type': 'policyNews',
          'group': 'hotspot'
        },{
          'url': [
            'http://www.51yala.com/list/list_141_1.Html',
            'http://www.51yala.com/list/list_176_1.html',
            'http://www.51yala.com/list/list_176_2.html',
            'http://www.51yala.com/list/list_176_3.html',
            'http://www.51yala.com/list/list_176_4.html',
            'http://www.51yala.com/list/list_176_5.html',

            'http://www.51yala.com/list/List_188_1.html',
            'http://www.51yala.com/list/List_188_2.html',
            'http://www.51yala.com/list/List_188_3.html',
            'http://www.51yala.com/list/List_188_4.html',
            'http://www.51yala.com/list/List_188_5.html',
            'http://www.51yala.com/list/List_188_6.html',
            'http://www.51yala.com/list/List_188_7.html',
        ],
          'pageFlag': '',
          'path': '//span[@class="STYLE3"]',
          'originName': '中国旅游网',
          'originUrl': "http://www.51yala.com",
          'type': 'policyNews',
          'group': 'custom'
        },{
          'url': ['http://www.cnta.com.cn/xxfb','http://www.cnta.com.cn'],
          'pageFlag': '',
          'path': '//article[@class="article"]',
          'originName': '中华人民共和国国家旅游局',
          'originUrl': "http://www.cnta.com.cn",
          'type': 'policyNews',
          'group': 'hotspot'
        },{
          'url': ['http://www.sohu.com/tag/70746','http://www.sohu.com/tag/5398','http://travel.sohu.com/'],
          'pageFlag': '',
          'path': '//article[@class="article"]',
          'originName': '搜狐旅游频道',
          'originUrl': "http://www.sohu.com",
          'type': 'travelNote',
          'group': 'custom'
        },{
          'url': ['http://www.dili360.com',
                  'http://www.dili360.com/travel/sight/20192.htm',
                  'http://www.dili360.com/travel/sight/20639.htm',
                  'http://www.dili360.com/travel/sight/20398.htm',
                  'http://www.dili360.com/travel/sight/20398.htm',
                  'http://www.dili360.com/travel/sight/20191.htm',
                  'http://www.dili360.com/travel/sight/20218.htm',
                  'http://www.dili360.com/travel/sight/20244.htm',
                  ],
          'pageFlag': 'article',
          'path': '//section',
          'originName': '国家地理',
          'originUrl': "http://www.dili360.com",
          'type': 'travelNote',
          'group': 'custom'
        },{
          'url': ['http://www.lotour.com/',
            'http://www.lotour.com/zhoubianyou/',
            'http://www.lotour.com/guoneiyou/',
            'http://www.lotour.com/zhengwen/x3765',
            'http://www.lotour.com/zhengwen/x3728',
            'http://www.lotour.com/zhengwen/x3732',],
          'pageFlag': '',
          'path': '//div[@class="ia-right"]',
          'originName': '乐途旅游网',
          'originUrl': "http://www.lotour.com",
          'type': 'policyNews',
          'group': 'custom'
        },{
          'url': ['http://www.lotour.com/',
            'http://www.lotour.com/zhoubianyou/',
            'http://www.lotour.com/guoneiyou/',
            'http://www.lotour.com/zhengwen/x3765',
            'http://www.lotour.com/zhengwen/x3728',
            'http://www.lotour.com/zhengwen/x3732',],
          'pageFlag': '',
          'path': '//div[@class="ia-right"]',
          'originName': '乐途旅游网',
          'originUrl': "http://www.lotour.com",
          'type': 'policyNews',
          'group': 'custom'
        },{
          'url': ['http://go.tuniu.com/',
            'http://trips.tuniu.com/',
            'http://www.tuniu.com/g2500/guide-0-0/',
            'http://www.tuniu.com/g170/guide-0-0/',
            # 'http://trips.tuniu.com/travels/index/ajax-list?sortType=1&page=1&limit=50',
            # 'http://trips.tuniu.com/travels/index/ajax-list?sortType=2&page=1&limit=50',
            # 'http://trips.tuniu.com/travels/index/ajax-list?sortType=3&page=1&limit=50',
            ],
          'pageFlag': '',
          'path': '//div[@class="detail-content"]',
          'originName': '途牛旅游网',
          'originUrl': "http://www.tuniu.com",
          'type': 'policyNews',
          'group': 'custom'
        },{
          'url': ['https://www.ly.com/travels/',
                  'https://www.ly.com/go/',
            ],
          'pageFlag': '',
          'path': '//div[@class="contentall"]',
          'originName': '同程网游记',
          'originUrl': "https://www.ly.com",
          'type': 'travelNote',
          'group': 'custom'
        },{
          'url': ['http://travel.sina.com.cn/',
            'http://travel.sina.com.cn/itinerary/',
            ],
          'pageFlag': '',
          'path': '//div[@id="artibody"]',
          'originName': '新浪旅游',
          'originUrl': "http://travel.sina.com.cn",
          'type': 'channelNews',
          'group': 'hotspot'
        },{
          'url': [
            'http://travel.qunar.com/?from=header',
            'http://travel.qunar.com/p-sf297123-zhejiang',
            'http://travel.qunar.com/p-sf297541-yunnan',
            'http://travel.qunar.com/p-sf297541-yunnan',
            'http://travel.qunar.com/p-sf297555-jiangsu',
            'http://travel.qunar.com/p-sf298482-hunan',
            'http://travel.qunar.com/p-cs299914-beijing',
            'http://travel.qunar.com/p-cs299878-shanghai',
            'http://travel.qunar.com/p-gj300667-zhongguo#placebottomNav',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/1.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/2.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/3.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/4.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/5.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/6.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/7.htm',
            'http://travel.qunar.com/travelbook/list/24-zhongguo-300667/hot_heat/8.htm',
        ],
          'pageFlag': 'youji',
          'path': '//div[@class="b_panel_schedule"]',
          'originName': '去哪儿游记',
          'originUrl': "https://www.qunar.com",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': [ 'http://travel.sina.com.cn/',
            'http://travel.sina.com.cn/itinerary/',
            ],
          'pageFlag': '',
          'path': '//div[@class="ebm-post ebm-article"]',
          'originName': '新浪旅游',
          'originUrl': "http://travel.sina.com.cn",
          'type': 'channelNews',
          'group': 'hotspot'
        },{
          'url': ['https://www.tripadvisor.cn/TourismBlog-g294211-China.html',
            ],
          'pageFlag': '',
          'path': '//div[@class="strategy-contents"]',
          'originName': '猫途鹰',
          'originUrl': "https://www.tripadvisor.cn",
          'type': 'video',
          'group': 'hotspot'
        },{
          'url': ['http://tc.hnntv.cn//ly/index.shtml',
            ],
          'pageFlag': '',
          'path': '//div[@class="voide"]',
          'originName': '旅游网视',
          'originUrl': "http://tc.hnntv.cn",
          'type': 'travelNote',
          'group': 'video'
        },{
          'url': ['http://www.lvye.cn/news/',
            ],
          'pageFlag': '',
          'path': '//table[@class="vwtb"]',
          'originName': '绿野户外',
          'originUrl': "http://www.lvye.cn",
          'type': 'outdoorNews',
          'group': 'hotspot'
        },{
          'url': ['http://www.mafengwo.cn/','http://www.mafengwo.cn/gonglve/',
            ],
          'pageFlag': '',
          'path': '//div[@class="vc_article"]',
          'originName': '蚂蜂窝',
          'originUrl': "http://www.mafengwo.cn",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': ['http://www.xout.cn/'
            ],
          'pageFlag': '',
          'path': '//div[@class="view"]',
          'originName': '极限户外网',
          'originUrl': "http://www.xout.cn",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': ['http://www.campingchina.cc/'
            ],
          'pageFlag': '',
          'path': '//div[@class="listtitxn"]',
          'originName': '露营中国网',
          'originUrl': "http://www.campingchina.cc",
          'type': 'outdoorNews',
          'group': 'hotspot'
        },{
          'url': ['http://travel.hexun.com/index.html'
            ],
          'pageFlag': '',
          'path': '//div[@class="art_context"]',
          'originName': '和讯商旅',
          'originUrl': "http://travel.hexun.com",
          'type': 'policyNews',
          'group': 'hotspot'
        },{
          'url': ['http://travel.china.com'
            ],
          'pageFlag': '',
          'path': '//div[@id="chan_newsDetail"]',
          'originName': '中华网旅游',
          'originUrl': "http://travel.china.com",
          'type': 'policyNews',
          'group': 'hotspot'
        },{
          'url': ['http://www.beibaotu.com/travel_notes'
            ],
          'pageFlag': '',
          'path': '//div[@id="content"]',
          'originName': '背包兔',
          'originUrl': "http://www.beibaotu.com",
          'type': 'travelNote',
          'group': 'hotspot'
        },{
          'url': ['http://www.roadqu.com/',
                  'http://www.roadqu.com/city/',
                  'http://www.roadqu.com/journey/',
            ],
          'pageFlag': '',
          'path': '//div[@id="journey-page-content"]',
          'originName': '路趣网',
          'originUrl': "http://www.roadqu.com/",
          'type': 'travelNote',
          'group': 'hotspot'
        },
    ]
    def getAllItems(self):
        items =models.item.objects.all()
        return items

    def getflagByUrl(self,originUrl):
        item=models.item.objects.filter(originUrl__icontains=originUrl)
        return item

    def getItemInfoByOriginUrl(self,originUrl):
        items=models.item.objects.filter(originUrl__startswith=originUrl)
        return items
